

<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
  <meta charset="utf-8">
  
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
  <title>geoslurp.db.initgeoslurpdb &mdash; geoslurp Wannabe v1.0 documentation</title>
  

  
  
    <link rel="shortcut icon" href="../../../_static/favicon.ico"/>
  
  
  

  

  
  
    

  

  
  
    <link rel="stylesheet" href="../../../_static/css/theme.css" type="text/css" />
  

  

  
        <link rel="index" title="Index"
              href="../../../genindex.html"/>
        <link rel="search" title="Search" href="../../../search.html"/>
    <link rel="top" title="geoslurp Wannabe v1.0 documentation" href="../../../index.html"/>
        <link rel="up" title="Module code" href="../../index.html"/> 

  
  <script src="../../../_static/js/modernizr.min.js"></script>

</head>

<body class="wy-body-for-nav" role="document">

   
  <div class="wy-grid-for-nav">

    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search">
          

          
            <a href="../../../index.html" class="icon icon-home"> geoslurp
          

          
          </a>

          
            
            
              <div class="version">
                1.0
              </div>
            
          

          
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../../../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

          
        </div>

        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
          
            
            
              
            
            
              <p class="caption"><span class="caption-text">Contents:</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../../introduction.html">An introduction to Geoslurp</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../installation.html">Installation of the geoslurp package and setting up the PostgreSQL instance</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../confsettings.html">Configuration</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../examples.html">Tutorial</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../reference.html">Reference Documentation</a></li>
</ul>

            
          
        </div>
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" role="navigation" aria-label="top navigation">
        
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="../../../index.html">geoslurp</a>
        
      </nav>


      
      <div class="wy-nav-content">
        <div class="rst-content">
          















<div role="navigation" aria-label="breadcrumbs navigation">

  <ul class="wy-breadcrumbs">
    
      <li><a href="../../../index.html">Docs</a> &raquo;</li>
        
          <li><a href="../../index.html">Module code</a> &raquo;</li>
        
      <li>geoslurp.db.initgeoslurpdb</li>
    
    
      <li class="wy-breadcrumbs-aside">
        
            
        
      </li>
    
  </ul>

  
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
            
  <h1>Source code for geoslurp.db.initgeoslurpdb</h1><div class="highlight"><pre>
<span></span><span class="c1"># This file is part of geoslurp.</span>
<span class="c1"># geoslurp is free software; you can redistribute it and/or</span>
<span class="c1"># modify it under the terms of the GNU Lesser General Public</span>
<span class="c1"># License as published by the Free Software Foundation; either</span>
<span class="c1"># version 3 of the License, or (at your option) any later version.</span>

<span class="c1"># geoslurp is distributed in the hope that it will be useful,</span>
<span class="c1"># but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<span class="c1"># MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU</span>
<span class="c1"># Lesser General Public License for more details.</span>

<span class="c1"># You should have received a copy of the GNU Lesser General Public</span>
<span class="c1"># License along with geoslurp; if not, write to the Free Software</span>
<span class="c1"># Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA</span>

<span class="c1"># Author Roelof Rietbroek (roelof@geod.uni-bonn.de), 2018</span>

<span class="kn">from</span> <span class="nn">geoslurp.db.inventory</span> <span class="k">import</span> <span class="n">Inventory</span>
<span class="kn">from</span> <span class="nn">geoslurp.db.settings</span> <span class="k">import</span> <span class="n">Settings</span>

<span class="c1"># from geoslurp.db.inventory import GSBase as gsbinv</span>
<span class="c1"># from geoslurp.db.settings import SettingsTable</span>
<span class="c1"># from geoslurp.db.settings import GSBase as gsbset</span>
<span class="c1">#test</span>

<div class="viewcode-block" id="initgeoslurpdb"><a class="viewcode-back" href="../../../reference/geoslurp.db.html#geoslurp.db.initgeoslurpdb.initgeoslurpdb">[docs]</a><span class="k">def</span> <span class="nf">initgeoslurpdb</span><span class="p">(</span><span class="n">conn</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Initiates main geoslurp admin structure&quot;&quot;&quot;</span>
    <span class="c1">#check if the admin schema exists and initiate this otherwise (note the first user who creates this owns it, so better make this an admin user!!)</span>
    <span class="k">if</span> <span class="n">conn</span><span class="o">.</span><span class="n">schemaexists</span><span class="p">(</span><span class="s1">&#39;admin&#39;</span><span class="p">):</span>
        <span class="c1">#quick return if the schema already exists</span>
        <span class="k">return</span>

    <span class="n">conn</span><span class="o">.</span><span class="n">CreateSchema</span><span class="p">(</span><span class="s1">&#39;admin&#39;</span><span class="p">)</span>

    <span class="c1">#initializes the inventory table so it gets created</span>
    <span class="n">inv</span><span class="o">=</span><span class="n">Inventory</span><span class="p">(</span><span class="n">conn</span><span class="p">)</span>


    <span class="c1">#initializes the settings table so it gets created</span>
    <span class="n">conf</span><span class="o">=</span><span class="n">Settings</span><span class="p">(</span><span class="n">conn</span><span class="p">)</span>

    <span class="c1"># gsbinv.metadata.create_all(conn.dbeng)</span>
    <span class="c1"># conn.dbeng.execute(&#39;GRANT ALL PRIVILEGES ON admin.inventory to geoslurp;&#39;)</span>
    <span class="c1"># conn.dbeng.execute(&#39;GRANT USAGE ON SEQUENCE admin.inventory_id_seq to geoslurp&#39;)</span>
    
    <span class="c1"># #create settings table</span>
    <span class="c1"># gsbset.metadata.create_all(conn.dbeng)</span>
    <span class="c1"># conn.dbeng.execute(&#39;GRANT ALL PRIVILEGES ON admin.settings to geoslurp&#39;)</span>
    <span class="c1"># conn.dbeng.execute(&#39;GRANT USAGE ON SEQUENCE admin.settings_id_seq to geoslurp&#39;)</span>

    <span class="c1">#create a &#39;default&#39; entry in the settings table</span>
    <span class="n">defaultentry</span><span class="o">=</span><span class="n">SettingsTable</span><span class="p">(</span><span class="n">user</span><span class="o">=</span><span class="s1">&#39;default&#39;</span><span class="p">,</span><span class="n">conf</span><span class="o">=</span><span class="p">{</span><span class="s2">&quot;CacheDir&quot;</span><span class="p">:</span><span class="s2">&quot;/tmp&quot;</span><span class="p">,</span><span class="s2">&quot;MirrorMaps&quot;</span><span class="p">:{</span><span class="s2">&quot;default&quot;</span><span class="p">:</span><span class="s2">&quot;$</span><span class="si">{HOME}</span><span class="s2">/geoslurpdata&quot;</span><span class="p">}})</span></div>

    <span class="c1"># ses=conn.Session()</span>
    <span class="c1"># ses.add(defaultentry)</span>
    <span class="c1"># ses.commit()</span>
    <span class="c1">#allow the geoslurp user to access the sequence generator</span>

</pre></div>

           </div>
           <div class="articleComments">
            
           </div>
          </div>
          <footer>
  

  <hr/>

  <div role="contentinfo">
    <p>
        &copy; Copyright 2020, Roelof Rietbroek.

    </p>
  </div>
  Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/snide/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>. 

</footer>

        </div>
      </div>

    </section>

  </div>
  


  

    <script type="text/javascript">
        var DOCUMENTATION_OPTIONS = {
            URL_ROOT:'../../../',
            VERSION:'Wannabe v1.0',
            COLLAPSE_INDEX:false,
            FILE_SUFFIX:'.html',
            HAS_SOURCE:  true,
            SOURCELINK_SUFFIX: '.txt'
        };
    </script>
      <script type="text/javascript" src="../../../_static/jquery.js"></script>
      <script type="text/javascript" src="../../../_static/underscore.js"></script>
      <script type="text/javascript" src="../../../_static/doctools.js"></script>

  

  
  
    <script type="text/javascript" src="../../../_static/js/theme.js"></script>
  

  
  
  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.StickyNav.enable();
      });
  </script>
   

</body>
</html>